package com.aheizi.oa.view.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aheizi.oa.base.BaseAction;
import com.aheizi.oa.domain.Forum;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class ForumManageAction extends BaseAction<Forum>{
	
	//列表
	public String list() throws Exception{
		List<Forum> forumList = forumService.findAll();
		ActionContext.getContext().put("forumList", forumList);
		return "list";
	}
	
	//删除
	public String delete() throws Exception{
		forumService.delete(model.getId()); 
		return "toList";
	}
	
	//添加页面
	public String addUI() throws Exception{
		return "saveUI";
	}
	
	//添加
	public String add() throws Exception{
		forumService.save(model);
		return "toList";
	}
	
	//修改页面
	public String editUI() throws Exception{
		//准备回显数据
		Forum forum = forumService.getById(model.getId());
//		ActionContext.getContext().put("forum", forum);   //可以用，不过要复杂一点
		ActionContext.getContext().getValueStack().push(forum); //回显的时候保存到值栈
		return "saveUI";
	}
	
	//修改
	public String edit() throws Exception{
		//从数据库中取出原对象
		Forum forum = forumService.getById(model.getId());
		
		//设置要修改的属性
		forum.setName(model.getName());
		forum.setDescription(model.getDescription());
		
		//保存到数据库
		forumService.update(forum);
		
		return "toList";
	}
	
	//上移
	public String moveUp() throws Exception{
		forumService.moveUp(model.getId());
		return "toList";
	}
	
	//下移
	public String moveDown() throws Exception{
		forumService.moveDown(model.getId());
		return "toList";
	}
}
